class Solution38 {
    public String countAndSay(int n) {
      if(n == 1) return "1" ; 
      String str = countAndSay(n-1) ; 
       return func(str);
    }
    private String func(String str){
        int len = str.length() ; 
        StringBuilder strbu = new StringBuilder() ;
        for(int i=0 ; i < len ; ){
            int count = 1;
            char ch = str.charAt(i) ; 
            i++ ;
            while(i<len && str.charAt(i) == ch){
                count++ ;
                i++ ;
            }
            strbu.append(count) ; 
            strbu.append(ch) ; 
        }
       return strbu.toString() ;
    }
}